# LuckPay Web Manage System
#
# Copyright (c) 2016 Lucky Byte, Inc.
#

# 检查身份证号码是否有效
window.validate_idno = (id_no, label) ->
    if id_no.length != 18
        return succ: false, errmsg: "#{label}身份证号码长度#{id_no.length}不等于18."

    coefficients = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ]
    cv = '10X98765432'
    sum = 0
    for v, i in coefficients
        sum += v * id_no[i]
    if cv[sum % 11] == id_no[17]
        return succ: true

    return succ: false, errmsg: "#{label}身份证号码校验失败."


# 校验银行卡号
window.validate_cardno = (card_no, label) ->
    reverse_no = card_no.split('').reverse().join('')
    sum = 0
    for i in [0 .. reverse_no.length - 1]
        v = parseInt reverse_no.charAt(i)
        if i % 2 == 1
            v *= 2
            v -= 9 if v >= 10
        sum += v
    return true if sum % 10 == 0

# 禁用表单中所有控件
window.freeze_form = (form) ->
    form.find('a').hide()
    form.find('.dropdown').not('.nofreeze')
        .addClass('disabled').css('opacity', '0.9')
        .find('input').attr('readonly', 'readonly')
    form.find('.input').not('.nofreeze')
        .addClass('disabled').css('opacity', '0.9')
        .find('input').attr('readonly', 'readonly')
    form.find('textarea').not('.nofreeze')
        .attr('readonly', 'readonly')
    form.find('.ui.checkbox').css('opacity', '0.9')


# 交易控制字段名称
window.trctl_fields = [
    "time_begin",       "time_end",
    "min_amt_per",      "max_amt_per",
    "min_amt_per2",     "max_amt_per2",
    "max_amt_minute",   "max_cnt_minute",
    "max_amt_day",      "max_cnt_day"
]
